﻿using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Effects;
using Microsoft.Graphics.Canvas.UI.Xaml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.Storage.Pickers;
using Windows.Storage.Streams;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Documents;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using 纸片人.win2dEffectControl.DataClass;

// The Templated Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234235

namespace 纸片人.win2dEffectControl
{
    public  class CanvasBitmapControl : EffectOutputControl
    {

      

        private Button selectButton;

        
        public CanvasBitmapControl()
        {
           
            this.DefaultStyleKey = typeof(CanvasBitmapControl);
            EffectData = new CanvasBitmapData();
        }

      

        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            selectButton = GetTemplateChildFormName<Button>(nameof(selectButton));
            selectButton.Click += SelectButton_Click;
            SetEffectName("基本图像", "CanvasBitmap");
        }

        private async void SelectButton_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker picker = new FileOpenPicker();
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".png");

            StorageFile file = await picker.PickSingleFileAsync();
            if (file == null)
                return;
            await ((CanvasBitmapData)EffectData).FileToSoftwareBitmap(file);
        }

     

       
    }
}
